import React from 'react';
import { loc, KFind, obj_str, ck_sn, ck_empty, useKForm, KDlg, KInput } from 'sui';

const DlgVal = (props) => {
    const form = useKForm(props.data);

    const ck = {
        sn : v => ck_sn(v, props.data, props.main),
        name : v => ck_empty(v),
        auth : v => ck_empty(v),
        passwd : v => {
            const e = ck_empty(v);
            if (e) {
                return e;
            }

            const dp = form.get("ckpasswd");
            if (v !== dp) {
                return loc("l_434");
            }

            return null;
        }
    };

    const isDis = () => {
        if (obj_str(props.data, "sn")) {
            return true;
        }

        return false;
    };

    return (
        <KDlg {...props} title={loc("l_191")} ck={ck} form={form}>
            <KInput label={`${loc("l_257")} SN`} form={form} name="sn" disabled={isDis()} width="w-px-dlg"/>
            <KInput label={loc("l_318")} form={form} name="name" width="w-px-dlg"/>
            <KFind label={loc("l_258")} form={form} name="auth" list={props.auth}/>
            <KInput label={loc("l_282")} form={form} name="passwd" type="password" width="w-px-dlg"/>
            <KInput label={loc("l_433")} form={form} name="ckpasswd" type="password" width="w-px-dlg"/>
        </KDlg>
    );
};

export {DlgVal};
